#pragma once
#include <Rz/Object.h>
#include <Rz/Graphics/Render/IRenderTarget2D.h>
#include <Rz/Graphics/Render/Libraries/OpenGL/GLTexture2D.h>

RZ_CLASS_FWD_DECL3(Rz, Graphics, Math, Size);

namespace Rz { namespace Graphics { namespace Render { namespace Libraries { namespace OpenGL {

class GLRenderTarget2D :
	virtual public GLTexture2D,
	public IRenderTarget2D
{
	public:
		friend class GLRenderDevice;

		RZ_RTTI(Rz::Graphics::Render::Libraries::OpenGL, GLRenderTarget2D);
		RZ_RTTI_IMPLEMENTS(GLTexture2D, IRenderTarget2D);
		RZ_RTTI_END;

		GLRenderTarget2D(IRenderDevice* renderDevice, const Math::Size& size, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, RenderTargetUsage usage);
		virtual ~GLRenderTarget2D();

		// IBindableResource
		virtual void Bind() override;
		virtual void Unbind() override;

	private:
		void SetFramebufferHandle(GLuint handle, u32 index);
		GLuint GetFramebufferHandle() const;

		static GLenum DepthFormatConversion(DepthFormat depthFormat);

		GLuint _framebufferHandle;
		GLuint _renderbufferHandle;
		GLenum _glDepthFormat;

		DepthFormat _depthFormat;
};

} } } } }
